home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#24 (Sep 87)
/
Monkey cdev source
/
MonkeyCdev.c
< prev
next >
Wrap
C/C++ Source or Header
|
1987-06-06
|
2KB
|
83 lines
/* Monkey CDEV
* by Jan Eugenides
* 6/6/87
*
* An example of adding a function to the
* Control Panel, and using the Macintosh II's
* SndPlay routine
*/
#include <MacTypes.h>
#include <pascal.h>
#include <MemoryMgr.h>
#include <OSUtil.h>
#include <ToolboxUtil.h>
#include <DialogMgr.h>
#include <EventMgr.h>
#include <SoundMgr.h>
/*First define some needed constants*/
enum{
initDev,
hitDev,
closeDev,
nulDev,
updateDev,
deActivDev,
keyEvtDev,
macDev
};
Handle InitStorage();
/*This is the main routine, the entry point for the CDEV*/
pascal Handle main(message,item,numItems,CPanelID,ep,cdevStorage,CPDialog)
int message,item,numItems,CPanelID;
EventRecord *ep;
Handle cdevStorage;
DialogPtr CPDialog;
{
if(message == macDev)return((Handle)1);
if(cdevStorage)
{
switch(message)
{
case initDev: /*Init message received, allocate some storage*/
cdevStorage = InitStorage();
if(cdevStorage)DoHit(1+numItems,numItems,CPDialog);
break;
case closeDev: /*Close message received, dispose of storage*/
DisposeStorage(cdevStorage);
cdevStorage = (Handle)0L;
break;
case hitDev: /*User clicked an item, handle it*/
DoHit(item,numItems,CPDialog);
break;
} /*end switch*/
}/*end else if*/
return(cdevStorage);
}
Handle InitStorage() /*ultra-simple storage allocation*/
{ /*The storage is not used in this example*/
return(NewHandle(16L));
}
DisposeStorage(h) /*Release our storage area*/
Handle h;
{
DisposHandle(h);
}
DoHit(item,numItems,CPDialog) /*Handle a click on one of our items*/
int item,numItems; /*This example has only one item, so it's*/
DialogPtr CPDialog; /*very simple*/
{
Handle soundH;
soundH = GetResource('snd ',4); /*there is a space after snd */
if(soundH)
SndPlay(0L,soundH,TRUE); /*play the monkey screech*/
}